﻿using Application.MainModule.CountriesManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Domain.MainModule.Countries;
using Domain.MainModule.Entities;

using Infraestructure.CrossCutting.IoC;

namespace Application.MainModule.Tests
{
    /// <summary>
    ///This is a test class for CountryManagemntServiceTest and is intended
    ///to contain all CountryManagemntServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CountryManagementServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for AddCountry
        ///</summary>
        [TestMethod()]
        public void AddCountry_Invoke_Test()
        {
            //Arrange
            ICountryManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICountryManagementService>();
            Guid countryId = Guid.Parse("ABCDF000-FFFF-5678-9123-EFAB567890AB");
            Country country = new Country()
            {
                CountryId = countryId,
                Name = "Felicidonia",
                IsEnabled = true
            };
            Country result = null;

            //Act
            target.AddCountry(country);
            result = target.FindCountryById(countryId);
            
            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(countryId, result.CountryId);
        }

        /// <summary>
        ///A test for ChangeCountry
        ///</summary>
        [TestMethod()]
        public void ChangeCountry_Invoke_Test()
        {
            //Arrange
            ICountryManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICountryManagementService>();
            Guid countryId = Guid.Parse("ABCDF000-1234-5678-9456-EFAB567890AB");
            Country country = null;
            Country result = null;

            //Act
            country = target.FindCountryById(countryId);
            country.Name = "Disneylandia";
            target.ChangeCountry(country);

            //Assert
            result = target.FindCountryById(countryId);
            Assert.IsNotNull(result);
            Assert.AreEqual("Disneylandia", result.Name);
        }

        /// <summary>
        ///A test for FindCountryByISOAlpha2
        ///</summary>
        [TestMethod()]
        public void FindCountryByISOAlpha2_Invoke_Test()
        {
            //Arrange
            ICountryManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICountryManagementService>();
            Country country = null;

            //Act
            country = target.FindCountryByISOAlpha2("ISO Alpha 2");

            //Assert
            Assert.IsNotNull(country);
            Assert.AreEqual("ISO Alpha 2", country.ISO3166_Alpha2);
        }

        /// <summary>
        ///A test for FindCountryByISOAlpha3
        ///</summary>
        [TestMethod()]
        public void FindCountryByISOAlpha3_Invoke_Test()
        {
            //Arrange
            ICountryManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICountryManagementService>();
            Country country = null;

            //Act
            country = target.FindCountryByISOAlpha3("ISO Alpha 3");

            //Assert
            Assert.IsNotNull(country);
            Assert.AreEqual("ISO Alpha 3", country.ISO3166_Alpha3);
        }

        /// <summary>
        ///A test for FindCountryByISONumeric
        ///</summary>
        [TestMethod()]
        public void FindCountryByISONumeric_Invoke_Test()
        {
            //Arrange
            ICountryManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICountryManagementService>();
            Country country = null;

            //Act
            country = target.FindCountryByISONumeric("ISO Numeric");

            //Assert
            Assert.IsNotNull(country);
            Assert.AreEqual("ISO Numeric", country.ISO3166_Numeric);
        }

        /// <summary>
        ///A test for FindCountryById
        ///</summary>
        [TestMethod()]
        public void FindCountryById_Invoke_Test()
        {
            //Arrange
            ICountryManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICountryManagementService>();
            Guid countryId = Guid.Parse("ABCDF000-1234-5678-9456-EFAB567890AB");
            Country country = null;

            //Act
            country = target.FindCountryById(countryId);

            //Assert
            Assert.IsNotNull(country);
            Assert.AreEqual(countryId, country.CountryId);
        }

        /// <summary>
        ///A test for FindCountryByName
        ///</summary>
        [TestMethod()]
        public void FindCountryByName_Invoke_Test()
        {
            //Arrange
            ICountryManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ICountryManagementService>();
            string countryName = "Argentina";
            Country country = null;

            //Act
            country = target.FindCountryByName(countryName);

            //Assert
            Assert.IsNotNull(country);
            Assert.AreEqual(countryName, country.Name);
        }
    }
}
